<template>
  <XtxBread>
    <XtxBreadItem to="/">首页</XtxBreadItem>
    <Transition name="fade-right" mode="out-in">
      <XtxBreadItem :key="cateInfo.fcate.id" v-if="cateInfo.fcate" :to="`/category/${cateInfo.fcate.id}`">{{
        cateInfo.fcate.name
      }}</XtxBreadItem>
    </Transition>
    <Transition name="fade-right" mode="out-in">
      <XtxBreadItem :key="cateInfo.scate.id" v-if="cateInfo.scate">{{ cateInfo.scate.name }}</XtxBreadItem>
    </Transition>
  </XtxBread>
</template>
<script>
import { useStore } from 'vuex'
import { useRoute } from 'vue-router'
import { computed } from 'vue'
export default {
  name: 'SubBread',
  setup() {
    const store = useStore()
    const route = useRoute()
    const cateInfo = computed(() => {
      const info = {
        fcate: {},
        scate: {}
      }
      store.state.cate.list.some(first => {
        const second =
          first.children &&
          first.children.find(item => {
            return item.id === route.params.id
          })

        if (second) {
          info.fcate = {
            id: first.id,
            name: first.name
          }
          info.scate = {
            id: second.id,
            name: second.name
          }
          return true
        }
      })
      return info
    })
    return { cateInfo }
  }
}
</script>
